﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Orchard.Themes;
using Orchard.Mvc;
using Orchard.DisplayManagement;
using Downplay.Origami;

namespace Downplay.Prototypes.Lens.Controllers
{
    /// <summary>
    /// Provides a new search page using Lens UI
    /// TODO: Will we need AJAX partials here, or will they fit in another system?
    /// </summary>
    public class SearchController : Controller
    {
        private readonly IShapeFactory shapeFactory;
        public SearchController(
            IShapeFactory _shapeFactory
        ) {
            Shape = shapeFactory = _shapeFactory;
        }
        public dynamic Shape { get; set; }

        /// <summary>
        /// Normal query method (search page)
        /// </summary>
        /// <returns></returns>
        [Themed]
        public ActionResult Query() {
            var shape = QueryShape();
            return new ShapeResult(this, (object)shape);
        }

        /// <summary>
        /// AJAX query method
        /// </summary>
        /// <returns></returns>
        [Ajax]
        [Themed]
        public ActionResult AjaxQuery() {
            var shape = QueryShape();
            return new ShapePartialResult(this, (object)shape);
        }
        /// <summary>
        /// AJAX search action, returns a HTML list of items
        /// </summary>
        /// <param name="query"></param>
        /// <param name="id">Id of content item to query available content</param>
        /// <param name="socket">Connector type to query allowable types</param>
        /// <returns></returns>
/*        [HttpGet]
        public ActionResult Query(string query, int? id = null, string socket = "") {
            return View("Shape", null);
        }
        */
        private object QueryShape() {
            var shape = Shape.Lens();
            return shape;
        }

    }
}
